package com.woniu.woniuproject.controller.admin;

import com.github.pagehelper.PageInfo;
import com.woniu.woniuproject.entity.Debt_info;
import com.woniu.woniuproject.service.DebtInfoService;
import com.woniu.woniuproject.utils.ResponseResult;
import com.woniu.woniuproject.vo.Page;
import com.woniu.woniuproject.vo.queryByok;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述:<br>
 * 〈〉
 *
 * @author 徐威
 * @create 2020/11/16
 * @since 1.0.0
 */
@RestController
@RequestMapping("debtInfo")
public class Debt_infoController {
    @Autowired
    DebtInfoService debtInfoService;

    /**
     * 功能待匹配和部分匹配查询
     * @param page 分页
     * @param debtTypeName 标的编号
     * @param matchedStatus 匹配状态
     * @return
     */
    @GetMapping("/mathched")
    public ResponseResult<PageInfo<Debt_info>> queryBystatus(Page page, String debtTypeName, String matchedStatus ){
        PageInfo<Debt_info> debt_infoPageInfo = debtInfoService.queryByAllbystatus(debtTypeName, matchedStatus, page);
        return new ResponseResult<>(debt_infoPageInfo);
    }

    /**
     * 加入匹配池
     * @param id
     * @return
     */
    @GetMapping("/matching/{id}")
    public ResponseResult modifyByStatus(@PathVariable int id){
        int i = debtInfoService.startMatching(id);
        int code = 500;
        if (i>0){
            code =200;
        }
        return new ResponseResult(code,"SAD");
    }
    @GetMapping("/cancel/{id}")
    public ResponseResult cancelByStatus(@PathVariable int id){
        int i = debtInfoService.cancelMatching(id);
        int code = 500;
        if (i>0){
            code =200;
        }
        return new ResponseResult(code,"SAD");
    }


    @GetMapping("/queryByok")
    public ResponseResult<PageInfo<Debt_info>> queryByok(queryByok querybyok){

        return new ResponseResult<>( debtInfoService.queryByok(querybyok));
    }


}
